class _BookViewModel:
    @classmethod
    def package_single(cls, data, keyword):
        formatted_info = {
            'book': [],
            'count': 0,
            'keyword': keyword
        }
        if data:
            formatted_info['book'] = [cls.__strip_info(data)]
            formatted_info['count'] = 1
        return formatted_info

    @classmethod
    def package_multiple(cls, data, keyword):
        formatted_info = {
            'book': [],
            'count': 0,
            'keyword': keyword
        }
        if data:
            formatted_info['book'] = [cls.__strip_info(dt) for dt in data['books']]
            formatted_info['count'] = data['count']
        return formatted_info

    @classmethod
    def __strip_info(cls, data):
        stripped_info = {
            'title': data['title'],
            'author': data['author'],
            'publisher': data['publisher'],
            'pages': data['pages'],
            'summary': data['summary'],
            'image': data['image'],
        }
        return stripped_info


class BookViewModel:
    def __init__(self, yushu_book):
        self.title = yushu_book['title']
        self.author = '、'.join(yushu_book['author'])
        self.publisher = yushu_book['publisher']
        self.price = yushu_book['price']
        self.pages = yushu_book['pages']
        self.summary = yushu_book['summary']
        self.image = yushu_book['image']
        self.isbn = yushu_book['isbn']
        self.pubdate = yushu_book['pubdate'] or '',
        self.binding = yushu_book['binding'] or '',

    @property
    def intro(self):
        return ' / '.join(filter(lambda x: True if x else False, [self.author, self.publisher, self.price]))


class BookCollection:
    def __init__(self):
        self.book = []
        self.total = 0
        self.keyword = ''

    def fill(self, yushu_book, keyword):
        self.book = [BookViewModel(book) for book in yushu_book.books]
        self.total = yushu_book.count
        self.keyword = keyword
